package com.luoshenshen.heart;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

import java.net.SocketAddress;

/**
 * @author ShenshenLuo
 * @date 2025/4/19 17:05
 **/
public class HeartDealHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        Channel channel = ctx.channel();
        SocketAddress socketAddress = channel.remoteAddress();
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            switch (event.state()) {
                case READER_IDLE:

                    System.out.println(socketAddress + "读空闲");
                    break;
                case WRITER_IDLE:
                    System.out.println(socketAddress + "写空闲");
                    break;
                default:
                    System.out.println(socketAddress + "全部空闲");
                    break;
            }
        }
    }
}
